//
//  WNXTabBarController.m
//  BSBDJ-1
//
//  Created by co on 16/3/11.
//  Copyright © 2016年 王南侠. All rights reserved.
//

#import "WNXTabBarController.h"
#import "WNXessenceViewController.h"
#import "WNXfriendTrendsViewController.h"
#import "WNXnewViewController.h"
#import "WNXmeViewController.h"

@implementation WNXTabBarController

-(void)viewDidLoad {
    
    [super viewDidLoad];
    
    [UINavigationBar appearance];
    
    // 通过appearance 统一设置所有 UITabBarItem的文字属性
    // 设置普通字体
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    // 设置选中字体
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    
    // 添加子控制器
    [self setupChildVc:[[WNXessenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon"];
    [self setupChildVc:[[WNXnewViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon"];
    [self setupChildVc:[[WNXfriendTrendsViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon"  selectImage:@"tabBar_friendTrends_click_icon"];

    [self setupChildVc:[[WNXmeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon"];
    
}



/**
 初始化子控制器
 */
-(void)setupChildVc: (UIViewController *)vc title:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage{
    
    vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:arc4random_uniform(100)/100.0];
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
    [self addChildViewController:vc];
}


@end
